package com.example.snackfood.dao;

import com.example.snackfood.entity.Products;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: snackFood
 * @description:
 * @author: lydms
 * @create: 2023-11-24 21:45
 **/

@Component
public class SnackFoodProductsDao {

    @Resource
    private MongoTemplate mongoTemplate;


    public void save(Products products) {
        mongoTemplate.save(products);
    }

    public void delete(Query query) {
        mongoTemplate.remove(query,Products.class);
    }

    public void update(Query query, Update update) {
        mongoTemplate.updateMulti(query,update,Products.class);
    }

    public Products get(Query query) {
        return mongoTemplate.findOne(query,Products.class);
    }

    public List<Products> findAll() {
        return mongoTemplate.findAll(Products.class);
    }
}
